package demo1;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;

public class TestThread2 extends Thread {
    private String url;
    private String name;
    @Override
    public void run() {
        WebDownload webdownload = new WebDownload();
        webdownload.download(url,name);
        System.out.println("正在下载文件"+name);
    }

    public static void main(String[] args) {
        TestThread2 t1 = new TestThread2("http://img.hb.aicdn.com/e62c9422ad024a8a73fdfa5ddb6274a153a2b9e56b95e-w8j1J8_fw320", "1.jpg");
        TestThread2 t2 = new TestThread2("https://i02piccdn.sogoucdn.com/f2e974d41cdbf4b6", "2.jpg");
        TestThread2 t3 = new TestThread2("https://i01piccdn.sogoucdn.com/37a201bd3e24fb8e", "3.jpg");
        t1.start();
        t2.start();
        t3.start();
    }
    public TestThread2(String url, String name){
        this.url = url;
        this.name = name;
    }

    public class WebDownload {
        void download(String url,String name){
            try {
                FileUtils.copyURLToFile(new URL(url),new File(name));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

